package org.wyz;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.wyz.mapreduce.joinwithcache.JoinWithCacheMapper;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

// 这个已经用不到了
public class JoinWithCache {
    private static final String[] ARGS = {"data/input/join-with-cache", "data/output/join-with-cache", "data/cache/join-with-cache/user_exam.csv"};

    public int run(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "join-with-cache");
        job.setJarByClass(this.getClass());

        job.setMapperClass(JoinWithCacheMapper.class);
        job.setNumReduceTasks(0);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        job.addCacheFile(new URI(args[2]));

        return job.waitForCompletion(true) ? 0 : 1;
    }

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {
        int res = new JoinWithCache().run(ARGS);
        System.exit(res);
    }
}
